package main

import (
	"flag"
	"github.com/golang/glog"
	"cloud_worm/util/unet/usocket"
	"cloud_worm/access/config"
	"sync"
	"cloud_worm/access/server"
	"cloud_worm/util/umodels"
)

const (
	configFile = "./conf/config.conf"
	
	version = 100100101
)

func main()  {
	// 日志相关的初始化
	flag.Parse()
	glog.MaxSize = 1024 * 1024 * 20

	usocket.SetOpenFileLimit()

	err := config.LoadConfig(configFile, version)
	if err != nil {
		glog.Fatal(err)
		return
	}

	var wg sync.WaitGroup
	server.DiagnoseSrv(&wg)

	// 启动协程，刷新router config信息
	dbConfig := umodels.DbInfo{
		RunMode: config.ConfInst.RunMode,
		UserName: config.ConfInst.Mysql.UserName,
		Password: config.ConfInst.Mysql.Password,
		Port: config.ConfInst.Mysql.Port,
		Database: config.ConfInst.Mysql.Database,
	}
	umodels.OrmInit(dbConfig)

	if err := server.AccessSrv(); err != nil {
		glog.Fatal(err)
		return
	}
	if err := server.RpcSrv(); err != nil {
		glog.Fatal(err)
		return
	}
	if err := server.StartPushClient(&wg); err != nil {
		glog.Fatal(err)
		return
	}

	wg.Wait()

	//select {}
	return
}